
			
			<div class="clear"></div> <!-- End .clear -->
			
			<div class="content-box"><!-- Start Content Box -->
				
				<div class="content-box-header">
					
					<h3>Content box</h3>
					
					<ul class="content-box-tabs"><!-- href must be unique and match the id of target div -->
						<li><a href="#tab2" class="default-tab">Forms</a></li>
					</ul>
					
					<div class="clear"></div>
					
				</div> <!-- End .content-box-header -->
				
				<div class="content-box-content">
					
					<div class="tab-content default-tab" id="tab2">
					
						<form action="" method="post" id="permission">
							
							<fieldset> <!-- Set class to "column-left" or "column-right" on fieldsets to divide the form into columns -->
								
								<p>
									<label>权限角色名称</label>
										<input class="text-input small-input" type="text" id="small-input" name="title" /> 
										<span id="hint"></span>
										<br /><small>权限角色名称不可重复</small>
								</p>
								
								<?php foreach($authc as $au):?>
								<input type="checkbox" name="auth_check" value="<?php echo $au['id']?>" style="cursor:pointer;"><?php echo $au['authname']?>

										<?php if(isset($au['child'])){ foreach($au['child'] as $auc):?>
										<input style="cursor:pointer;" type="checkbox" name="auth_check" value="<?php echo $auc['id']?>"><?php echo $auc['authname']?>

										<?php endforeach ;}?>	
									</br>
								<?php endforeach;?>	
								<br /><small>至少选择一项权限</small>
								<p>
									<input class="button" type="submit" value="全选" id="cheAll" />
								
									<input class="button" type="submit" value="全不选" id="cheNone" />
								
									<input class="button" type="submit" value="反选" id="invert" />
								</p>
								
								<p>
									<input class="button" type="submit" value="提交" id="submit" />
								</p>
								
							</fieldset>
							
							<div class="clear"></div><!-- End .clear -->
							
						</form>
						
					</div> <!-- End #tab2 -->        
					
				</div> <!-- End .content-box-content -->
				
			</div> <!-- End .content-box -->
			
			
			<script type="text/javascript">

				$("#cheAll").click(function(){
					$("input:auth_check").each(function(){
						$(this).attr("checked",true);
					})

					return false;
				})

				$("#cheNone").click(function(){
					$("input:auth_check").each(function(){
						$(this).attr("checked",false);
					})

					return false;
				})

				$("#invert").click(function(){
					$("input:auth_check").each(function(){
						var inv = $(this).attr("checked");
						if(inv){
							$(this).attr("checked",false);
						}else{
							$(this).attr("checked",true);
						}
						
					})

					return false;
				})

				//判断权限名唯一性
				$("#small-input").blur(function(){
					var authname = $(this).val();
					if(authname==''){
						$("#hint").text('权限名称不可为空').css('color','red');
						return false;
					}
					
					$.ajax({
						url:"",

						type:'post',

						data: {auth:authname},

						dataType: 'json',

						success :function(msg){
							if(msg==1){

								$("#hint").text('权限名称已存在').css('color','red');

								return false;
							}else{

								$("#hint").text('权限名称可用').css('color','green');
							}
						},
					})

					return false;
				})

				$("#permission").submit(function(){
					// alert('sss');return false;
					// alert($("input:checkbox:checked").val());
					// return false;
					var hint = $("#hint").text();

					if(hint!='权限名称可用'){
						return false;
					}



					var check ='';
					
 					 $('input[name="auth_check"]:checked').each(function () {
 					 			

						check += $(this).val()+',';	///$(this)当前项
					});
 					


 					 var per_name = $("#small-input").val();
					
 					 $.ajax({
 					 	url:"",

 					 	type: "post",

 					 	data : {per_na :per_name,checks:check},

 					 	dataType : 'json',

 					 	success:function(msg){
 					 		if(msg==1){
 					 			alert('添加成功');return false;
 					 		}else{
 					 			alert('添加失败');return false;
 					 		}
 					 	}
 					 })








 					 return false;

				})

				//点击父级权限名自动选取所有子集权限
				$("input:auth_check").click(function(){

					var aut_id = $(this).val();

					var checked = $(this).attr("checked");


					$.ajax({
						url:"",

						type:'post',

						data:{caut_id : aut_id},

						dataType: 'json',

						success: function(msg){
							var array = new Array();

							


							for(var i =0 ; i<msg.length ; i++){

								array[i] = msg[i].id;
							}

							

							$("input:auth_check").each(function(){
								var cval = $(this).val();
								
								
								if($.inArray(cval,array)!=-1){

									// $(this).attr("checked" , true);
									// $(this).click();

									// console.log(checked);	
									if(checked){
										$(this).attr("checked" , true);
									}else{
										$(this).attr("checked" , false);
									}
								}

							})
						
							
						},
						error :function(msg){
							alert('error');
						}

					})	
				})


			</script>
			
			
			
			<!-- End Notifications -->
			
			